package com.huike.web.controller.business;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.domain.vo.TbBusinessVO;
import com.huike.business.service.TbBusinessTrackRecordService;
import com.huike.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商机跟进记录Controller
 * @date 2023-04-28
 */
@Api(tags = "跟进记录相关接口")
@Slf4j
@RestController
@RequestMapping("/business/record")
@RequiredArgsConstructor
public class TbBusinessTrackRecordController {
    private final TbBusinessTrackRecordService tbBusinessTrackRecordService;

    /**
     * 新增商机跟进记录接口
     * @param businessTrackVo
     * @return
     */
    // TODO 有bug 待解决，同时要更新商机表
    @ApiOperation("新增商机跟进记录接口")
    @PostMapping()
    public AjaxResult add(@RequestBody BusinessTrackVo businessTrackVo){
        log.info("新增商机跟进记录接口:{}",businessTrackVo);

        tbBusinessTrackRecordService.add(businessTrackVo);

        return AjaxResult.success();
    }


    /**
     *查询商机跟进记录表接口
     * @param businessId
     * @return
     */
    @ApiOperation("查询商机跟进记录列表接口")
    @GetMapping("/list")
    public AjaxResult<List<TbBusinessTrackRecord>> list(String businessId){
        log.info("查询商机跟进记录列表接口：{}",businessId);
        LambdaQueryWrapper<TbBusinessTrackRecord> wrapper = new LambdaQueryWrapper<>();
        //查询条件
        wrapper.eq(businessId != null,TbBusinessTrackRecord::getBusinessId,businessId);
        //查询商机根基记录表
        List<TbBusinessTrackRecord> trackRecords = tbBusinessTrackRecordService.list(wrapper);
        //返回数据
        return AjaxResult.success(trackRecords);
    }

    /**
     *获取商机跟进记录详细信息接口
     * @param id
     * @return
     */
    @ApiOperation("获取商机跟进记录详细信息接口")
    @GetMapping("/{id}")
    public AjaxResult<List<TbBusinessTrackRecord>> find(@PathVariable Long id){
        log.info("获取商机跟进记录详细信息接口：{}",id);
        LambdaQueryWrapper<TbBusinessTrackRecord> wrapper = new LambdaQueryWrapper<>();
        //查询条件
        wrapper.eq(id != null,TbBusinessTrackRecord::getId,id);
        //查询商机根基记录表
        List<TbBusinessTrackRecord> trackRecords = tbBusinessTrackRecordService.list(wrapper);
        //返回数据
        return AjaxResult.success(trackRecords);
    }


}
